/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Client_GUI.SavingBook;

import Client_GUI.Unity;
import Interface.*;
import Server.*;
import Server.DTO.SavingBook_DTO;
import java.awt.event.KeyEvent;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.sql.Date;
import java.text.SimpleDateFormat;
import javax.swing.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.swingx.JXDatePicker;

/**
 *
 * @author 10520_000
 */
public class JP_AddSavingBook extends org.jdesktop.swingx.JXPanel {

    Registry registry;
    IRemoteSavingBook rsavingbook;
    IRemoteCustomer rcustomer;
    IRemoteSavingType rsavingtype;
    IRemoteParameter rparamater;
    ArrayList arr_Names = null;
    ArrayList arr_Terms = null;

    /**
     * CreatesJP_SavingTypeAddCusomerAddCusomer
     */
    public JP_AddSavingBook() throws RemoteException, NotBoundException {
        initComponents();
        registry = LocateRegistry.getRegistry("127.0.0.1");
        rsavingbook = (IRemoteSavingBook) registry.lookup("SavingBook");
        rcustomer = (IRemoteCustomer) registry.lookup("Customer");
        rsavingtype = (IRemoteSavingType) registry.lookup("SavingType");
        rparamater = (IRemoteParameter) registry.lookup("Parameter");
        //gan loai tiet kiem vao combobox
        arr_Names = rsavingtype.GetNames();
        for (int i = 0; i < arr_Names.size(); i++) {
            cbo_TenLoaiTietKiem.addItem(arr_Names.get(i));
        }
        //gan ky han vao combobox
        arr_Terms = rsavingtype.GetTerms();

        for (int i = 0; i < arr_Terms.size(); i++) {
            if (((Integer) arr_Terms.get(i)).intValue() == 0) {
                cbo_KyHan.addItem("Khong Ky Han");
            } else {
                cbo_KyHan.addItem(arr_Terms.get(i) + " Thang");
            }

        }

        if (cbo_TenLoaiTietKiem.getSelectedItem().toString().trim().compareTo("khong ky han") != 0) {
            cbo_KyHan.removeItem("Khong Ky Han");
        } else {

        }

        //gan ngay mac dinh
        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat dayFormat = new SimpleDateFormat("dd/MM/yyyy");
        JXNgayMo.setDate(date);
        //
        //ArrayList arr = rsavingtype.GetNames();
    }

    public Date ConvertDateSQL(JXDatePicker date) {
        return new Date(date.getDate().getYear(), date.getDate().getMonth(), date.getDate().getDate());
    }

    public Date DateAfterCurrentDate(Date date, int month) {
        return new Date(date.getYear(), date.getMonth() + month, date.getDate());
    }

    public void ClearAll() {
        this.txt_Hoten.setText("");
        this.txt_SoCMND.setText("");
        this.cbo_TenLoaiTietKiem.setSelectedItem(cbo_TenLoaiTietKiem.getItemAt(0));
        this.cbo_KyHan.setSelectedItem(cbo_KyHan.getItemAt(0));
        this.txt_SoTienGuiBanDau.setText("");
        this.JXNgayMo.setDate(new java.util.Date());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txt_Hoten = new javax.swing.JTextField();
        txt_SoCMND = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        JXNgayMo = new org.jdesktop.swingx.JXDatePicker();
        txt_SoTienGuiBanDau = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cbo_TenLoaiTietKiem = new javax.swing.JComboBox();
        cbo_KyHan = new javax.swing.JComboBox();
        btn_Them = new javax.swing.JButton();
        btn_NhapLai = new javax.swing.JButton();
        btn_thoat = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin khách hàng"));

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel2.setText("Tên Chủ Sổ");

        txt_Hoten.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        txt_Hoten.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_HotenKeyTyped(evt);
            }
        });

        txt_SoCMND.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        txt_SoCMND.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_SoCMNDKeyTyped(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel3.setText("Số CMND");

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel4.setText("Tên Loại Tiết Kiệm");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel5.setText("Số Tiền Gửi Ban Đầu");

        jLabel6.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel7.setText("Kỳ Hạn");

        txt_SoTienGuiBanDau.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N

        jLabel8.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel8.setText("Ngày Mở");

        cbo_TenLoaiTietKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbo_TenLoaiTietKiemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addGap(72, 72, 72))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txt_Hoten, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txt_SoCMND, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(JXNgayMo, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txt_SoTienGuiBanDau, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(cbo_TenLoaiTietKiem, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbo_KyHan, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(41, 41, 41))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txt_Hoten, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txt_SoCMND, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cbo_TenLoaiTietKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(cbo_KyHan, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addGap(2, 2, 2)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txt_SoTienGuiBanDau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                        .addComponent(jLabel8)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(JXNgayMo, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

        btn_Them.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/32/Small_AddCustomer.png"))); // NOI18N
        btn_Them.setText("Thêm ");
        btn_Them.setToolTipText("");
        btn_Them.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btn_Them.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btn_Them.setIconTextGap(40);
        btn_Them.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ThemActionPerformed(evt);
            }
        });

        btn_NhapLai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/32/Small_Update.png"))); // NOI18N
        btn_NhapLai.setText("Nhập lại");
        btn_NhapLai.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btn_NhapLai.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btn_NhapLai.setIconTextGap(40);
        btn_NhapLai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_NhapLaiActionPerformed(evt);
            }
        });

        btn_thoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/32/Small_Close.png"))); // NOI18N
        btn_thoat.setText("Thoát");
        btn_thoat.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btn_thoat.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btn_thoat.setIconTextGap(40);
        btn_thoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_thoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btn_Them, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_NhapLai, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_thoat, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(86, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(btn_Them, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btn_NhapLai, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btn_thoat, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(33, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btn_ThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ThemActionPerformed
        // TODO add your handling code here:
        SavingBook_DTO info = new SavingBook_DTO();
        String str_TypeName = cbo_TenLoaiTietKiem.getSelectedItem().toString().trim();
        String str_Terms = cbo_KyHan.getSelectedItem().toString().trim();
        String[] str_split = null;
        try {
            do {
                
                if (txt_Hoten.getText().compareTo("") == 0) {
                    JOptionPane.showMessageDialog(null, "Ho Ten Khong Duoc De Trong");
                } else {
                    if (txt_SoCMND.getText().compareTo("") == 0) {
                        JOptionPane.showMessageDialog(null, "So CMND Khong Duoc De Trong");
                    } else if (txt_SoTienGuiBanDau.getText().compareTo("") == 0) {
                        JOptionPane.showMessageDialog(null, "So Tien Gui Ban Dau Khong Duoc De Trong");
                    }
                }
            } while (txt_Hoten.getText().compareTo("") == 0 || txt_SoCMND.getText().compareTo("") == 0 || txt_SoTienGuiBanDau.getText().compareTo("") == 0);
            //gán mã sổ
            info.setBookID("");
            //gán mã khách hàng
            info.setCustomerID(rcustomer.GetCustomerID(txt_Hoten.getText(), txt_SoCMND.getText()));
            //gán mã loại tiết kiệm
            if (str_TypeName.compareToIgnoreCase("Khong Ky Han") == 0) {
                info.setTypeID(rsavingtype.GetSavingType(str_TypeName, 0));
            } else {
                str_split = str_Terms.split(" ");
                info.setTypeID(rsavingtype.GetSavingType(str_TypeName, Integer.parseInt(str_split[0])));
            }

            //gán ngày mở sổ
            info.setOpeningDate(ConvertDateSQL(JXNgayMo));

            if (rsavingtype.FindByTypeID(info.getTypeID()).getTerm() != 0) {
                //gán ngày bắt đầu tính lãi
                info.setInterestStartingDate(DateAfterCurrentDate(ConvertDateSQL(JXNgayMo), rparamater.FindAll().getThoiGianBatDauTinhLaiCoKyHan()));
                //gán ngày kết thúc
                info.setDueDate(DateAfterCurrentDate(ConvertDateSQL(JXNgayMo), rsavingtype.FindByTypeID(info.getTypeID()).getTerm()));
            } else {
                //gán ngày kết thúc
                info.setDueDate(ConvertDateSQL(JXNgayMo));
                //gán ngày bắt đầu tính lãi
                info.setInterestStartingDate(DateAfterCurrentDate(ConvertDateSQL(JXNgayMo), rparamater.FindAll().getThoiGianBatDauTinhLaiKhongKyHan()));
            }
            info.setAccountBalance(Float.parseFloat(txt_SoTienGuiBanDau.getText()));
            info.setSBStatus(true);

            //kiem tra thong tin nhap 
            

            //
            if (info.getCustomerID().compareTo("") == 0) {
                //khong ton tai khach hang
                JOptionPane.showMessageDialog(null, "Khach Hang Khong Ton Tai Tren He Thong\nNhap Lai Thong Tin Khach Hang");
            } else {
                if (rsavingbook.CountSavingBook(info.getCustomerID()) < 5) {
                    if (info.getTypeID().compareTo("") == 0) {
                        JOptionPane.showMessageDialog(null, "Loai Tiet Kiem Khong Ton Tai\nVui Long Chon Lai Ten Loai Tiet Kiem ");
                    } else {
                        //kiem tra so tien gui ban dau
                        if (Float.parseFloat(txt_SoTienGuiBanDau.getText()) < rparamater.FindAll().getSoTienGuiToiThieu()) {
                            JOptionPane.showMessageDialog(null, "Số Tiền Gửi Ban Đầu Phải >= " + rparamater.FindAll().getSoTienGuiToiThieu());
                        } else {
                            JOptionPane.showMessageDialog(null, rsavingbook.CountSavingBook(info.getBookID()));
                            if (rsavingbook.CountSavingBook(info.getBookID()) < 5) {
                                rsavingbook.Insert(info);
                                JOptionPane.showMessageDialog(null, "Thêm Sổ Tiết Kiệm Thành Công");
                                Unity.AddPanel(this, new JP_SavingBook());
                            } else {
                                JOptionPane.showMessageDialog(null, "Số Lương Sổ Tiết Kiệm Phải <=" + rparamater.FindAll().getSoLuongSoTietKiemToiDa());
                            }

                        }
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Khong The Them So Moi\nSo luong So Tiet Kiem Phai <= " + rparamater.FindAll().getSoLuongSoTietKiemToiDa());
                }

            }
        } catch (RemoteException ex) {
            Logger.getLogger(JP_AddSavingBook.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NotBoundException ex) {
            Logger.getLogger(JP_AddSavingBook.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_ThemActionPerformed

    private void btn_NhapLaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_NhapLaiActionPerformed
        // TODO add your handling code here:
        ClearAll();
    }//GEN-LAST:event_btn_NhapLaiActionPerformed

    private void btn_thoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_thoatActionPerformed
        try {
            // TODO add your handling code here:
            Unity.AddPanel(this, new JP_SavingBook());
        } catch (RemoteException ex) {
            Logger.getLogger(JP_AddSavingBook.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NotBoundException ex) {
            Logger.getLogger(JP_AddSavingBook.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.setVisible(true);
    }//GEN-LAST:event_btn_thoatActionPerformed

    private void cbo_TenLoaiTietKiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbo_TenLoaiTietKiemActionPerformed
        // TODO add your handling code here:
        boolean flag = false;
        String str_typename = cbo_TenLoaiTietKiem.getItemAt(cbo_TenLoaiTietKiem.getSelectedIndex()).toString().trim();
        if (str_typename.compareToIgnoreCase("CO KY HAN") == 0) {
            cbo_KyHan.removeItem("Khong Ky Han");
            cbo_KyHan.setEnabled(true);
            txt_SoTienGuiBanDau.setEditable(true);
            txt_SoTienGuiBanDau.setText("");
        } else {

            try {
                cbo_KyHan.setEnabled(false);
                for (int i = 0; i < cbo_KyHan.getItemCount(); i++) {
                    if (cbo_KyHan.getItemAt(i).toString().compareToIgnoreCase("Khong Ky Han") == 0) {
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    cbo_KyHan.addItem("Khong Ky Han");
                }
                cbo_KyHan.setSelectedItem("Khong Ky Han");
                txt_SoTienGuiBanDau.setText(rparamater.FindAll().getSoTienGuiToiThieu() + "");
                txt_SoTienGuiBanDau.setEditable(false);
            } catch (RemoteException ex) {
                Logger.getLogger(JP_AddSavingBook.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }//GEN-LAST:event_cbo_TenLoaiTietKiemActionPerformed

    private void txt_SoCMNDKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_SoCMNDKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if (!(Character.isDigit(c) || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_SPACE)) {
            evt.consume();
        }
    }//GEN-LAST:event_txt_SoCMNDKeyTyped

    private void txt_HotenKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_HotenKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if (Character.isDigit(c)) {
            evt.consume();
        }
    }//GEN-LAST:event_txt_HotenKeyTyped


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXDatePicker JXNgayMo;
    private javax.swing.JButton btn_NhapLai;
    private javax.swing.JButton btn_Them;
    private javax.swing.JButton btn_thoat;
    private javax.swing.JComboBox cbo_KyHan;
    private javax.swing.JComboBox cbo_TenLoaiTietKiem;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txt_Hoten;
    private javax.swing.JTextField txt_SoCMND;
    private javax.swing.JTextField txt_SoTienGuiBanDau;
    // End of variables declaration//GEN-END:variables
}
